package com.jinx.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jixia
 * @date 2021/10/21 14:43
 * @description
 */
@Slf4j
public class ExcelListener extends AnalysisEventListener {
    private List<Object> data = new ArrayList<>();

    @Override
    public void invoke(Object object, AnalysisContext context) {
        log.info("解析到一条数据:{}", JSON.toJSONString(object));
        data.add(object);
    }

    /**
     * 所有数据解析完成了 都会来调用
     *
     * @param context
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info("所有数据解析完成！");
    }

    public List<Object> getDatas() {
        return data;
    }

    public void setDatas(List<Object> datas) {
        this.data = datas;
    }
}
